/*
 * @Author: youngqj youngqj@126.com
 * @Date: 2024-11-02 18:07:42
 * @LastEditors: youngqj youngqj@126.com
 * @LastEditTime: 2024-12-04 17:46:03
 * @Description:
 *
 * Copyright © Zhejiang Xiaoqu Information Technology Co., Ltd, All Rights Reserved.
 */
package dto

import (
	"fmt"
	"time"

	"xiaoquio/web/core/utils"
	modle "xiaoquio/web/model"
)

type MerchantDTO struct {
	ID           string `json:"id"` // 加密后的ID
	MerchantName string `json:"merchant_name"`
	Phone        string `json:"phone"`
	StartTime    string `json:"StartTime"`
	CreateAt     string `json:"create_at"`
	Invalid      int    `json:"is_valid"`
	LastLogin    string `json:"last_login"`
	ExpiredTime  string `json:"expired_time"`
	LastLoginIp  string `json:"last_login_ip"`
	URL          string `json:"url"`
}

func GetMerchantDTO(merchant modle.Merchants) MerchantDTO {
	userID := fmt.Sprintf("%v", merchant.ID)
	encodingUserID, _ := utils.Encrypt(userID)
	createTime := time.Unix(int64(merchant.CreateAt/1000), 0).Format("2006-01-02 15:04:05")
	startTime := time.Unix(int64(merchant.StartTime/1000), 0).Format("2006-01-02 15:04:05")
	lastLogin := time.Unix(int64(merchant.LastLogin/1000), 0).Format("2006-01-02 15:04:05")
	expiredTime := time.Unix(int64(merchant.ExpiredTime/1000), 0).Format("2006-01-02 15:04:05")
	url := "merchant/info/" + encodingUserID

	return MerchantDTO{
		ID:           encodingUserID, // 使用你的加密函数
		MerchantName: merchant.MerchantName,
		Phone:        merchant.Phone,
		CreateAt:     createTime,
		StartTime:    startTime,
		Invalid:      merchant.Invalid,
		LastLogin:    lastLogin,
		URL:          url,
		LastLoginIp:  merchant.LastLoginIP,
		ExpiredTime:  expiredTime,
	}
}
